Class LogUtil

java.lang.Object
edu.claflin.finder.log.LogUtil

public class LogUtil extends Object
Logging utility for documenting the state of the program. This simple custom built logging utility outputs to a file the steps involved in the program. It may also be configured to output to the terminal as well.
Version:
3.1 May 28, 2015
Author:
Charles Allen Schultz II
  • Field Details

    • path

      public static String path
      TEST
    • bW

      private final BufferedWriter bW
      The BufferedWriter used to log to a file.
    • logToFile

      private boolean logToFile
      The value representing if logging to a file is enabled. Defaults to true and is only set to false due to a malfunction in the BufferedWriter.
    • logToTerminal

      private boolean logToTerminal
      The value representing if logging to the terminal is enabled. Defaults to true.
    • maxGranularity

      private final LogLevel maxGranularity
      The maximum granularity of the logging utility. Anything greater will be ignored.
    • terminalLogs

      private final HashMap<LogType,Boolean> terminalLogs
      The HashMap used for determining which of the logging outputs are logged to the terminal.
    • fileLogs

      private final HashMap<LogType,Boolean> fileLogs
      The HashMap used for determining which of the logging outputs are logged to a file.
  • Constructor Details

    • LogUtil

      public LogUtil(LogLevel maxGranularity, boolean[] fileLogs, boolean[] terminalLogs)
      Constructs the logging utility.
      Parameters:
      maxGranularity - the maximum granularity of the log messages.
      fileLogs - the boolean array containing four values.
      terminalLogs - the boolean array containing four values.
    • LogUtil

      public LogUtil(LogLevel maxGranularity, boolean logToTerminal)
      Constructs the logging utility. Allows the user to specify which outputs are logged to the terminal and which are logged to the file.
      Parameters:
      maxGranularity - the maximum granularity of the log messages.
      logToTerminal - the boolean value indicating if logging to terminal should be enabled.
  • Method Details

    • setFileLogs

      private void setFileLogs(boolean[] fileLogs)
      Sets the FileLogs HashMap for selective logging to the file.
      Parameters:
      fileLogs - the boolean array containing four values.
    • setTerminalLogs

      private void setTerminalLogs(boolean[] terminalLogs)
      Sets the TerminalLogs HashMap for selective terminal logging.
      Parameters:
      terminalLogs - the boolean array containing four values.
    • destroyLogToFile

      public void destroyLogToFile()
      Destroys the Logging to File functionality of the log engine. Sets to false the boolean value indicating that logging to a file is enabled. It also closes the BufferedWriter to free the resource.
    • destroyLogToTerminal

      public void destroyLogToTerminal()
      Destroys the Logging to Terminal functionality of the log engine. Sets to false the boolean value indicating that logging to the terminal is enabled.
    • destroy

      public void destroy()
      Destroys all logging functionality of the log engine. A convenience method that calls both destroyLogToTerminal() and destroyLogToFile().
    • reportProblem

      private void reportProblem(String problem, String solution)
      Used to report problems with the logging engine to the terminal. Reporting is done to the terminal since most likely the BufferedWriter is experiencing an error.
      Parameters:
      problem - the String representing the problem that occurred.
      solution - the String representing the solution the program utilized.
    • log

      private void log(LogType type, LogLevel granularity, String detail)
      Used to log data. Contains the logic for logging both to the terminal and to a file. This method is private so that a user may not pass incorrect LogType objects to the method. Instead, there exist public methods that call this method appropriately.
      Parameters:
      type - the LogType object representing the level of detail for the log.
      granularity - the LogLevel object representing how granular this message is.
      detail - the String representing the data to be logged.
    • logError

      public void logError(LogLevel level, String detail)
      Logs an ERROR message. Used by the user to log error messages. Calls log(LogType, LogLevel, String) for the user.
      Parameters:
      level - the level of granularity of this message.
      detail - the String representing the data to be logged.
    • logInfo

      public void logInfo(LogLevel level, String detail)
      Logs an INFO message. Used by the user to log info messages. Calls log(LogLevel, String) for the user.
      Parameters:
      level - the level of granularity of this message.
      detail - the String representing the data to be logged.
    • logAlgo

      public void logAlgo(LogLevel level, String detail)
      Logs an ALGO message. Used by the user to log algorithm messages. Calls log(LogLevel, String) for the user.
      Parameters:
      level - the level of granularity of this message.
      detail - the String representing the data to be logged.
    • logGraph

      public void logGraph(LogLevel level, String detail)
      Logs a GRPH message. Used by the user to log graph messages. Calls log(LogLevel, String) for the user.
      Parameters:
      level - the level of granularity of this message.
      detail - the String representing the data to be logged.